package com.smile.controller;

import cn.hutool.core.bean.BeanUtil;
import com.smile.commons.page.R;
import com.smile.model.dto.request.SetAlarmReceptionSettingRequestDTO;
import com.smile.model.response.response.GetAlarmReceptionSettingResponseDTO;
import com.smile.model.request.SetAlarmReceptionSettingRequest;
import com.smile.model.response.GetAlarmReceptionSettingResponse;
import com.smile.model.response.GetReachTargetPointActionResponse;
import com.smile.service.AlarmReceptionSettingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/alarmReceptionSetting")
public class AlarmReceptionSettingController {

    @Autowired
    private AlarmReceptionSettingService alarmReceptionSettingService;

    @PostMapping("/setAlarmReceptionSetting")
    public R<Void> setAlarmReceptionSetting(@RequestBody SetAlarmReceptionSettingRequest setAlarmReceptionSettingRequest) {
        SetAlarmReceptionSettingRequestDTO setAlarmReceptionSettingRequestDTO = BeanUtil.copyProperties(setAlarmReceptionSettingRequest, SetAlarmReceptionSettingRequestDTO.class);
        Boolean result = alarmReceptionSettingService.setAlarmReceptionSetting(setAlarmReceptionSettingRequestDTO);
        if (result) {
            return R.ok();
        } else {
            return R.fail();
        }
    }

    @PostMapping("/getAlarmReceptionSetting")
    public R<GetAlarmReceptionSettingResponse> getAlarmReceptionSetting() {
        GetAlarmReceptionSettingResponseDTO getAlarmReceptionSettingResponseDTO = alarmReceptionSettingService.getAlarmReceptionSetting();
        GetAlarmReceptionSettingResponse getAlarmReceptionSettingResponse = BeanUtil.copyProperties(getAlarmReceptionSettingResponseDTO, GetAlarmReceptionSettingResponse.class);
        List<GetReachTargetPointActionResponse> getReachTargetPointActionResponses = BeanUtil.copyToList(getAlarmReceptionSettingResponseDTO.getGetReachTargetPointActions(), GetReachTargetPointActionResponse.class);
        getAlarmReceptionSettingResponse.setGetReachTargetPointActions(getReachTargetPointActionResponses);
        return R.ok(getAlarmReceptionSettingResponse);
    }

}
